﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations.Schema;
#if !NETFX_CORE
using System.Data.Entity;
#endif
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Entry;
using Cofe.Core.EntryType;
using Cofe.Core.Implements;
using Cofe.Data;

namespace Cofe.Media.Implements
{
#if !NETFX_CORE
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEMEDIA)]
    public class EFMediaInfoConfig : IDatabaseConfigurator
    {
        public void OnDatabaseCreating(CofeDbContext context)
        {            
        }

        public void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var cofeSystemInfoConfig = modelBuilder.Entity<CofeSystemInfo>();

            cofeSystemInfoConfig.Map<MediaInfo>(m =>
            {
                //m.MapInheritedProperties();
                m.ToTable("MediaInfo");
            });

            var mediaInfoConfig = modelBuilder.Entity<MediaInfo>();
            mediaInfoConfig.Property(e => e.Width);
            mediaInfoConfig.Property(e => e.Height);



            cofeSystemInfoConfig.Map<ImageInfo>(m =>
            {
                //m.MapInheritedProperties();
                m.Requires("Discriminator").HasValue(Cofe.Media.MediaTypes.Image);                
                m.ToTable("ImageInfo");
            });

            var imageInfoConfig = modelBuilder.Entity<ImageInfo>();
            imageInfoConfig.Property(e => e.CameraModel).HasMaxLength(100);
            imageInfoConfig.Property(e => e.CameraMaker).HasMaxLength(100);
            imageInfoConfig.Property(e => e.Aperture);
            imageInfoConfig.Property(e => e.FNumber);
            imageInfoConfig.Property(e => e.ExposureTime);
            imageInfoConfig.Property(e => e.ISO);
            imageInfoConfig.Property(e => e.FocalLength);
            imageInfoConfig.Property(e => e.Flash);
            imageInfoConfig.Property(e => e.DateTime);
        }

    }
#endif
}
